// pages/order/order.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list:[],
        status:['全部','待审核','通过','拒绝','完成'],
        handIndex:0,
        showQrcode: false,
        qrcodeUrl: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        //获取手机号
        /* wx.showLoading({
          title: '加载中',
        })
        console.log("信息",wx.getStorageSync('userinfo'));
        var phone = wx.getStorageSync('userinfo').user
        wx.request({
          url: 'http://127.0.0.1:5000/mini/visitorquery',
          method:"POST",
          data:{
              phone:phone
          },success:(res)=>{
              wx.hideLoading()
              console.log(res);
              if(res.data){
                this.setData({
                    list:res.data
                })
              }else{
                  wx.showToast({
                    title: '错误',
                    icon:"none"
                  })
              }

          },fail:(res)=>{
              wx.hideLoading()
              console.log(res);
          }
        }) */
        this.collectAll()
    },
    bindSelect(e){
        var index = e.currentTarget.dataset.index
        console.log(index);
        this.setData({
            handIndex:index
        })
        if(index == 0){
            this.collectAll()
        }else{
            var value = this.data.status[index]
            this.collectOne(value)
        }
    },
   //获取全部
   collectAll(){
    wx.showLoading({
        title: '加载中',
      })
      console.log("信息",wx.getStorageSync('userinfo'));
      var phone = wx.getStorageSync('userinfo').user
      wx.request({
        url: 'http://127.0.0.1:5000/mini/visitorquery',
        method:"POST",
        data:{
            phone:phone
        },success:(res)=>{
            wx.hideLoading()
            console.log(res);
            if(res.data){
              this.setData({
                  list:res.data
              })
            }else{
                wx.showToast({
                  title: '错误',
                  icon:"none"
                })
            }

        },fail:(res)=>{
            wx.hideLoading()
            console.log(res);
        }
      })
   },
   collectOne(value){
    wx.showLoading({
        title: '加载中',
      })
      console.log("信息",wx.getStorageSync('userinfo'));
      var phone = wx.getStorageSync('userinfo').user
      wx.request({
        url: 'http://127.0.0.1:5000/mini/visitorquone',
        method:"POST",
        data:{
            phone:phone,
            value:value
        },success:(res)=>{
            wx.hideLoading()
            console.log(res);
            if(res.data){
              this.setData({
                  list:res.data
              })
            }else{
                wx.showToast({
                  title: res.data.message,
                  icon:'none'
                })
                this.setData({
                    list:[]
                })
            }

        },fail:(res)=>{
            wx.hideLoading()
            console.log(res);
        }
      })
   },
   bindDelet(e){
       wx.showModal({
         title: '确定删除？',
         complete: (res) => {
           if (res.cancel) {
             wx.showToast({
               title: '删除取消',
               icon:"none"
             })
           }
           if (res.confirm) {
            wx.showLoading({
                title: '稍等',
              })
              var id = e.currentTarget.dataset.id
              console.log(id);
              wx.request({
                url: 'http://127.0.0.1:5000/mini/delorder',
                method:"POST",
                data:{
                    id:id
                },success:(res)=>{
                    wx.hideLoading()
                    console.log("删除成功",res);
                    wx.showToast({
                      title: '删除成功',
                    })
                    this.onLoad()
                },fail:(res)=>{
                    wx.hideLoading()
                    console.log(res);
                }
              })
           }
         }
       })
       
   },
   showQrcodeModal(e) {
       const url = e.currentTarget.dataset.qrcode;
       this.setData({
           showQrcode: true,
           qrcodeUrl: url
       });
   },
   hideQrcodeModal() {
       this.setData({
           showQrcode: false,
           qrcodeUrl: ''
       });
   }
})